import { Button } from 'antd';
import { useDebounceRequest } from '@/hooks/utils-hook';

const textFetchFn = (data: { name: string }, type: string) => {
	console.log(data);
	return new Promise<{ code: number; data: any; success: boolean }>((resolve) => {
		setTimeout(() => {
			resolve({ code: 200, data: {}, success: true });
		}, 2000);
	});
};

const RequestDebounce = () => {
	const { loading, requestFn } = useDebounceRequest(textFetchFn);

	// const { loading, runAsync } = useRequest(textFetchFn);

	// const [btnLoading, setLoading] = useState(false);

	const foo = async () => {
		const { data } = await requestFn({ name: 'frank' }, 'aaa');
		console.log(data);
	};

	return (
		<Button loading={loading} onClick={foo}>
			发送请求
		</Button>
	);
};

export default RequestDebounce;
